﻿namespace Gnivc.CarDealership.Api.Domain.Primitives;

public abstract class EntityBase
{
    public Guid Id { get; protected set; }
    
    public bool IsDeleted { get; set; }
    public DateTime CreatedAt { get; protected set; }

    protected EntityBase() { }

    protected EntityBase(Guid id)
    {
        Id = id;
        CreatedAt = DateTime.UtcNow;
    }

    public override bool Equals(object? obj)
    {
        return obj is EntityBase entity &&
               Id.Equals(entity.Id);
    }

    public override int GetHashCode()
    {
        return HashCode.Combine(Id);
    }

    public static bool operator ==(EntityBase left, EntityBase right)
    {
        if (ReferenceEquals(left, null))
            return ReferenceEquals(right, null);

        return left.Equals(right);
    }

    public static bool operator !=(EntityBase left, EntityBase right)
    {
        return !(left == right);
    }
}
